package com.codergd.gra.controller;

import com.codergd.gra.bean.Administrator;
import com.codergd.gra.service.AdministratorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/admin")
public class AdministratorController {
    @Autowired
    private AdministratorService administratorService;

    @PostMapping("/isLogin")
    public int isLogin(String iphone, @RequestParam("password") String pwa){
        return administratorService.isLogin(iphone, pwa);
    }

    @RequestMapping("/registered")
    public int registered(Administrator administrator){
        return administratorService.registered(administrator);
    }

    //根据手机号查找id
    @PostMapping("/selectId")
    public int selectId(HttpServletRequest request){
        return administratorService.selectId(request.getParameter("iphone"));
    }

//
//    @PostMapping("/insertType")
//    public int insertType(@RequestBody String name){
//        return administratorService.insertType(name);
//    }

    //根据id查找state
    @PostMapping("/state")
    public int selectState(int id){
        return administratorService.selectState(id);
    }

    //根据状态查询
    @PostMapping("/bystate")
    public List<Administrator> selectByState(int state){
        return administratorService.selectByState(state);
    }

    //查询全部
    @PostMapping("/all")
    public List<Administrator> selectAll(){
        return administratorService.selectAll();
    }

    //根据账号查询
    @PostMapping("/iphone")
    public List<Administrator> selectByIphone(String iphone){
        return administratorService.selectByIphone(iphone);
    }

    //两个条件
    @PostMapping("/selectTo")
    public List<Administrator> selectTo(String iphone,int state){
        return administratorService.selectTo(iphone,state);
    }

    //修改管理员状态
    @PostMapping("/updateState")
    public int updateState(int id,int state){
        return administratorService.updateState(id,state);
    }
}
